$(function () {
    $(document).click(function () {
        $("#foregroundSearchContent",parent.document).hide();
        $("#pageStart",parent.document).val("1")
    });
    parent.$(document).click(function () {
        $("#foregroundSearchContent",parent.document).hide();
        $("#pageStart",parent.document).val("1")
    });
    $("#foregroundSearchAll",parent.document).click(function () {
        var customerPhone = $("#foregroundInputPublic", parent.document).val();
        var str = customerPhone.replace(/(^\s*)|(\s*$)/g, "");
        if (customerPhone == null || customerPhone == "") {
            alert("请输入电话号码！");
            return;
        }
        if (!(/^\d{5,11}$/).test(str)) {
            alert("电话为5到11位的数字，请重新输入...");
            return;
        }
        if(str.length > 0 && str.length < 7 || str.length > 8 && str.length < 11){
            if (confirm("当前输入的号码为"+str.length+"位数，确定要匹配吗？")) {
                var index = layer.open({
                    type: 2,
                    title: '预约客户电话匹配',
                    area: ['45%', '60%'],
                    fix: true,
                    maxmin: true,
                    content: Feng.ctxPath + '/customer/to_reservation_matching/' + str
                });
                this.layerIndex = index;
            }
        }else {
            var index = layer.open({
                type: 2,
                title: '预约客户电话匹配',
                area: ['45%', '60%'],
                fix: true,
                maxmin: true,
                content: Feng.ctxPath + '/customer/to_reservation_matching/' + str
            });
            this.layerIndex = index;
        }
    });
    //进入详情
    $("#foregroundSearchContent", parent.document).on('click','.marketSearchShop',function () {
        var reservationId=$(this).attr('id');
        $.ajax({
            url: Feng.ctxPath + "/consultantTwo/getdcsByReservationId",
            type: "post",
            data: {
                "id": reservationId
            },
            success: function (data) {
                if (data == 1) {
                    var index = layer.open({
                        type: 2,
                        title: '到店客户详情',
                        area: ['100%', '100%'],
                        fix: true,
                        maxmin: true,
                        content: Feng.ctxPath + '/customerDetails/to_openByReservationId/' + reservationId+'/0'
                    });
                    this.layerIndex = index;
                }else{
                    alert("请先联系前台客服匹配建档！");
                    return;
                }
            }
        });
    });
    //重咨
    $("#foregroundSearchContent", parent.document).on('click','.insertReDiagnosis',function (e) {
        e.stopPropagation();
        var id = $(this).parents('.marketSearchShop').attr('id');
        $("#foregroundSearchContent",parent.document).hide();
        var index = layer.open({
            type: 2,
            title: '患者重咨',
            area: ['35%', '50%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/customer/to_reconsulting/'+id
        });
        this.layerIndex = index;
    });
    //复诊
    $("#foregroundSearchContent", parent.document).on('click','.customerReconsulting',function (e) {
        e.stopPropagation();
        var id = $(this).parents('.marketSearchShop').attr('id');
        $("#foregroundSearchContent",parent.document).hide();
        var index = layer.open({
            type: 2,
            title: '复诊预约',
            area: ['70%', '95%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/doctorLooked/subsequent_info2/' +id+'/1' ,
            success: function(layero, index){
                var index = layer.getFrameIndex(window.name);
                layer.close(index);
            }
        });
        this.layerIndex = index;
    });
});